﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/UserEdit.Master" Inherits="System.Web.Mvc.ViewPage<SDT.Site.Areas.User.ViewModels.OrderIndexViewModels>" %>
<%@ Import Namespace="SDT.Lib.Helpers" %>
<%@ Import Namespace="SDT.Lib.Paging" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Đơn hàng
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Header" runat="server">
    Danh sách đơn hàng
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="Message" runat="server">
    <%=ViewData["MessageInfo"]!=null? "<p class='perror'>"+Html.Encode(ViewData["MessageInfo"])+"</p>":string.Empty%>  
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="Toolbar" runat="server">
     
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%if(ViewData["MessageInfo"]==null){ %>
    <form action="" method="post" name="adminForm" id="adminForm">
        <table width="100%">
	        <tr>
	            <td width="220">
			        <%= Html.RadioButton("durationType", "0", Model.InYear > 0 ? false : true, new { id = "duration" })%>Chọn giai đoạn
			        <%= Html.RadioButton("durationType", "1",Model.InYear>0? true: false, new { id = "year" })%>Chọn theo năm
		        </td>
		        <td>
			        <div id="select_duration" <%=Model.InYear>0 ? "style=\"display:none\"":"style=\"display:block\"" %>>
				        Từ <%= Html.TextBox("fromDate", (Model.FromDate != DateTime.MinValue && Model.FromDate !=null)? Model.FromDate.ToString("dd/MM/yyyy") : "", new { @class = "datepicker", style = "width:80px" })%> đến <%= Html.TextBox("toDate", (Model.ToDate != DateTime.MinValue && Model.ToDate != null) ? Model.ToDate.ToString("dd/MM/yyyy") : "", new { @class = "datepicker", style = "width:80px" })%>
			        </div>
			        <div id="select_year" <%=Model.InYear>0 ? "style=\"display:block\"":"style=\"display:none\"" %>>
				        <select id="inYear" name="inYear">
					        <option value="">-- Năm --</option>
					        <% foreach (var year in Model.OperationDurations) { %>
					        <option value="<%= year.ToString() %>" <%=Model.InYear>0 && Model.InYear==year ? "selected=\"selected\"":"" %>><%= year.ToString() %></option>
					        <% } %>
				        </select>						
			        </div>
		        </td>
		        <td align="left"><%=Html.TextBox("Keyword", Model.Keyword, new { style = "width:100px" })%><input type="submit" value="Tìm kiếm" /></td>
	        </tr>
        </table>
        <script type="text/javascript">
            $(document).ready(function() {
                $.datepicker.setDefaults($.datepicker.regional['vi']);
                $(".datepicker").datepicker({
                    dateFormat: "dd/mm/yy",
                    changeMonth: true,
                    showOn: "button",
                    buttonImage: "/Images/calendar.gif",
                    buttonImageOnly: true,
                    changeYear: true
                });
                $(".datepicker").mask("99/99/9999");
                $("#duration").click(function() {
                    $("#select_duration").show();
                    $("#select_year").hide();
                });
                $("#year").click(function() {
                    $("#select_duration").hide();
                    $("#select_year").show();
                });
            });		
        </script>
        <table width="100%" class="tblprice">
	        <tr>
		        <th width="10" align="right">
			        STT
		        </th>
		        <th width="30"></th>				
		        <th style="width: 200px">
			        <%= Html.Sort("Đơn hàng", "OrderName", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
		        </th>
		        <th >
			        <%= Html.Sort("Trạng thái", "Status", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
		        </th>
		        <th>
			        <%= Html.Sort("Ngày đặt hàng", "AddDate", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
		        </th>
				
		        <th>
			        Tổng tiền
		        </th>
		        <th>
					<%= Html.Sort("Mã bưu điện", "EmsCode", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
				</th>
		        <th>
			        <%= Html.Sort("ID", "ID", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
		        </th>
	        </tr>
        <% 
	        int i = 0;
	        foreach (var item in Model.Orders) {
		        i++;
        %>		
	        <tr>
		        <td align="right" style="width: 30px">
			        <%= i.ToString() %>
		        </td>				
		         <td align="center" style="width: 26px">
			        <%= Html.ActionImage("Xóa", "icon-24-delete.png", "User/Order", "Delete", new Dictionary<string, object>() { { "id", item.ID }})%>
		        </td>
		        <td>
			        <%= Html.ActionLink(item.OrderName, "Details", new { id = item.ID,area="User" })%>
		        </td>				
		        <td >
			        <%= Html.Encode(item.Status>0? Model.OrderStatus[item.Status]:string.Empty)%>
		        </td>
		        <td>
			        <%= Html.Encode(string.Format("{0:dd/MM/yyyy}", item.AddDate)) %>
		        </td>				
		        <td >
					<%var total =item.TotalValue.HasValue? item.TotalValue.Value: item.OrderDetails.Sum(e => e.Price * e.Quantity); %>
                     <%=string.Format("{0:0,0.0}",total) %>                       
				</td>
				<td><%=Html.Encode(item.EmsCode) %></td>
		        <td style="width: 30px">
			        <%= Html.Encode(item.ID) %>
		        </td>
	        </tr>
	    
        <% } %>

        </table>
        <%= Html.Hidden("order")%>
        <%= Html.Hidden("orderDir")%>
        <table width="100%">
            <tr>
                <td align="center">
             
                <div class="pager">
                <label>Hiển thị #</label>
                    <%
                        int[] pageSizeList = {1, 5, 10, 15, 20, 25, 50, 100};
                    %>
                    <%= Html.DropDownList("PageSize", new SelectList(pageSizeList, Model.Orders.PageSize), new { onchange = "document.adminForm.submit();" })%>

                    <%= Html.Pager(Model.Orders.PageSize, Model.Orders.PageNumber, Model.Orders.TotalItemCount)%>
                    </div>
                </td>
            </tr>
        </table>
    </form>
 <% } %>
</asp:Content>
